import config
import webapi
import util


def get_issuecomment_data(issuecomment_url, start_time):
    api_data = webapi.get_issuecomment_data(issuecomment_url, start_time)
    data_df = util.clean_issuecomment_data(api_data)
    return data_df


def main(config):
    for _ in config['repository_list']:
        issuecomment_url = config['base_url'] + '/repos{}/issues/comments'.format(_)
        data = get_issuecomment_data(issuecomment_url, config['plan']['start_time'])
        data.to_csv(config['data_path']['issuecomments'].format(_.split('/')[-1]) + '.csv')
        # data.to_excel(config['data_path']['issuecomments'].format(_.split('/')[-1]) + '.xlsx')


if __name__ == '__main__':
    _config = config.get_config()
    main(_config)
